package com.muyu.user.domain;

import java.math.BigDecimal;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import lombok.Data;
import java.io.Serial;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.experimental.SuperBuilder;
import com.muyu.user.domain.model.SysUserLevelSaveModel;
import com.muyu.user.domain.model.SysUserLevelEditModel;
import com.muyu.common.core.web.domain.BaseEntity;

/**
 * 用户等级数据库映射对象 sys_user_level
 *
 * @author liuguoqiang
 * @date 2025-09-14
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sys_user_level")
@EqualsAndHashCode(callSuper = true)
public class SysUserLevel extends BaseEntity {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 等级ID
     */
    @Excel(name = "等级ID")
    @TableId(value = "level_id",type = IdType.AUTO)
    private Long levelId;

    /**
     * 等级名称
     */
    @Excel(name = "等级名称")
    private String levelName;

    /**
     * 等级编码
     */
    private String levelCode;

    /**
     * 等级图标
     */
    @Excel(name = "等级图标")
    private String levelIcon;

    /**
     * 等级背景图
     */
    private String levelBackground;

    /**
     * 等级值
     */
    private Long levelValue;

    /**
     * 最低积分要求
     */
    private Long minPoints;

    /**
     * 最高积分要求
     */
    private Long maxPoints;

    /**
     * 折扣率
     */
    @Excel(name = "折扣率")
    private BigDecimal discountRate;

    /**
     * 解锁经验值
     */
    @Excel(name = "解锁经验值")
    private Long unlockExperience;

    /**
     * 等级描述
     */
    private String description;

    /**
     * 排序
     */
    private Long sortOrder;

    /**
     * 是否显示（0隐藏 1显示）
     */
    private String isShow;

    /**
     * 状态（0正常 1停用）
     */
    @Excel(name = "状态", readConverterExp = "0=正常,1=停用")
    private String status;

    /**
     * 添加构造器
     */
    public static SysUserLevel saveModelBuild(SysUserLevelSaveModel saveModel){
        return SysUserLevel.builder()
            .levelId(saveModel.getLevelId())
            .levelName(saveModel.getLevelName())
            .levelIcon(saveModel.getLevelIcon())
                .levelCode(saveModel.getLevelCode())
            .discountRate(saveModel.getDiscountRate())
            .unlockExperience(saveModel.getUnlockExperience())
            .description(saveModel.getDescription())
            .sortOrder(saveModel.getSortOrder())
            .status(saveModel.getStatus())
            .build();
    }

    /**
     * 修改构造器
     */
    public static SysUserLevel editModelBuild(SysUserLevelEditModel editModel){
        return SysUserLevel.builder()
            .levelId(editModel.getLevelId())
            .levelId(editModel.getLevelId())
            .levelName(editModel.getLevelName())
            .levelIcon(editModel.getLevelIcon())
                .levelCode(editModel.getLevelCode())
            .discountRate(editModel.getDiscountRate())
            .unlockExperience(editModel.getUnlockExperience())
            .description(editModel.getDescription())
            .sortOrder(editModel.getSortOrder())
            .status(editModel.getStatus())
            .build();
    }

}
